/**
 * Created on 2017/01/21.
 */

function sleep(n)
{
    var start = new Date().getTime();
    while (true) if (new Date().getTime() - start > n) break;
}

function trim(str)
{
    // 删除左右两端的空格
    return str.replace(/(^\s*)|(\s*$)/g, '');
}

function ltrim(str)
{
    // 删除左边的空格
    return str.replace(/(^\s*)/g, '');
}

function rtrim(str)
{
    // 删除右边的空格
    return str.replace(/(\s*$)/g, '');
}

function getNowFormatDate()
{
    var date = new Date();
    var seperator1 = "-";
    var seperator2 = ":";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9)
    {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9)
    {
        strDate = "0" + strDate;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
    return currentdate;
}

function getNowFormatDateTime()
{
    var date = new Date();
    var seperator1 = "-";
    var seperator2 = ":";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9)
    {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9)
    {
        strDate = "0" + strDate;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
        + " " + date.getHours() + seperator2 + date.getMinutes()
        + seperator2 + date.getSeconds();
    return currentdate;
}

function prefixInteger(num, length)
{
    // 仅限于数字
    // prefixInteger(10, 4)  - > "0010"

    return (num / Math.pow(10, length)).toFixed(length).substr(2);
}

function prefixInteger(str, length)
{
    // 可传任何类型数据
    // prefixInteger("abc", 6) - > "000abc"

    return Array(length + 1).join("0").split("").concat(String(str).split("")).slice(-length).join("");
}

function isEmptyObject(e)
{
    var t;
    for (t in e)
        return !1;
    return !0
}

function browerPlatform()
{
    var ua = navigator.userAgent;
    var ipad = ua.match(/(iPad).*OS\s([\d_]+)/),
        isIphone = !ipad && ua.match(/(iPhone\sOS)\s([\d_]+)/),
        isAndroid = ua.match(/(Android)\s+([\d.]+)/),
        isMobile = isIphone || isAndroid;

    return {
        isIphone: isIphone,
        isAndroid: isAndroid,
        isMobile: isMobile
    }

    /*
     if(isMobile) {
     location.href = 'http://m.domain.com';
     }else{
     location.href = 'http://www.domain.com';
     ｝
     //或者单独判断iphone或android
     if(isIphone){
     //code
     else if(isAndroid){
     //code
     }else{
     //code
     }
     */
}